from pprint import pprint #格式化输出
#根据grade排序
classes = [
    {"name": "n_2", "age": 24, "grade": "B"},
    {"name": "n_3", "age": 27, "grade": "A"},
    {"name": "n_4", "age": 21, "grade": "C"},
    {"name": "n_5", "age": 25, "grade": "B"},
    {"name": "n_6", "age": 23, "grade": "D"},
    {"name": "n_7", "age": 26, "grade": "B"},
    {"name": "n_8", "age": 27, "grade": "A"},
    {"name": "n_9", "age": 20, "grade": "B"},
]
classes.sort(key = lambda x: x['grade'])

pprint(list(classes))


#filter语句过筛选出grade A
f = filter(lambda x: True if x["grade"] ==  "A" else False, classes)
pprint(list(f))

# map 函数age + 1
def age(item):
    item['age'] = item['age'] + 1
    return item

new_class = map(age, classes)
pprint(list(new_class))



#fibo 函数
def Fibo(x):
    if x <= 1:
        return 1
    else:
        return Fibo(x - 1) + Fibo(x - 2)

for i in range(11):
    print((Fibo(i)))